import request from "@/utils/request";
import type {
  GetHospitalSetListParams,
  GetHospitalSetListResponse,
  AddHospitalSetParams,
  HospitalSetItem,
  UpdateHospitalSetParams,
} from "./types";

enum ApiPath {
  GetHospitalSetList = "/admin/hosp/hospitalSet",
  AddHospitalSet = "/admin/hosp/hospitalSet/save",
  GetHospitalSetById = "/admin/hosp/hospitalSet/get",
  UpdateHospitalSet = "/admin/hosp/hospitalSet/update",
  RemoveHospitalSet = "/admin/hosp/hospitalSet/remove",
  BatchRemoveHospitalSet = "/admin/hosp/hospitalSet/batchRemove",
}

// 获取医院设置列表
// 函数参数：如果是2个或2个以下，就声明参数。如果是3个或3个以上，就定义对象接受
export const reqGetHospitalSetList = ({
  page,
  limit,
  hosname,
  hoscode,
}: GetHospitalSetListParams) => {
  // { page, limit, hosname, hoscode } 语法：对函数的第一个参数进行解构赋值
  return request.get<any, GetHospitalSetListResponse>(
    ApiPath.GetHospitalSetList + `/${page}/${limit}`,
    {
      params: {
        hosname,
        hoscode,
      },
    }
  );
};

// 添加医院设置
export const reqAddHospitalSet = (data: AddHospitalSetParams) => {
  return request.post<any, null>(ApiPath.AddHospitalSet, data);
};

// 通过id获取医院设置
export const reqGetHospitalSetById = (id: number) => {
  return request.get<any, HospitalSetItem>(
    ApiPath.GetHospitalSetById + `/${id}`
  );
};

// 修改医院设置
export const reqUpdateHospitalSet = (data: UpdateHospitalSetParams) => {
  return request.put<any, null>(ApiPath.UpdateHospitalSet, data);
};

// 删除医院设置
export const reqRemoveHospitalSet = (id: number) => {
  return request.delete<any, null>(ApiPath.RemoveHospitalSet + `/${id}`);
};

// 批量删除医院设置
export const reqBatchRemoveHospitalSet = (idList: number[]) => {
  return request.delete<any, null>(ApiPath.BatchRemoveHospitalSet, {
    data: idList,
  });
};
